@extends('admin.main')
@section('body')
    <div class="main-title">
        <h2>分类管理</h2>
    </div>

    <!-- 表格列表 -->
    <div class="tb-unit posr">
        <div class="tb-unit-bar">
            <a class="btn" href="{{urlAdmin('goodsCategory','getAdd')}}">新 增</a>
        </div>
        <div class="category">
            <div class="hd cf">
                <div class="fold">折叠</div>
                <div class="order">排序</div>
                <div class="order">发布</div>
                <div class="name">名称</div>
            </div>
            @if(count($tree))
                @foreach($tree as $v)
                    <dl class="cate-item">
                        <dt class="cf">
                        <form action="{{urlAdmin('GoodsCategory','postEdit')}}" method="post">
                            <div class="btn-toolbar opt-btn cf">
                                <a title="编辑"
                                   href="{{urlAdmin('GoodsCategory','getEdit',['id'=>$v['id'],'pid'=>$v['pid']])}}">编辑</a>
                                <a title="{{show_status_op($v['status'])}}"
                                   href="{{urlAdmin('GoodsCategory','anySetStatus',['ids'=>$v['id'],'status'=>abs(1-$v['status'])])}}"
                                   class="ajax-get">{{show_status_op($v['status'])}}</a>
                                <a title="删除" href="{{urlAdmin('GoodsCategory','getRemove',['id'=>$v['id']])}}"
                                   class="confirm ajax-get">删除</a>
                                <a title="移动"
                                   href="{{urlAdmin('GoodsCategory','getOperate',['type'=>'move','from'=>$v['id']])}}">移动</a>
                                <a title="合并"
                                   href="{{urlAdmin('GoodsCategory','getOperate',['type'=>'merge','from'=>$v['id']])}}">合并</a>
                            </div>
                            <div class="fold"><i></i></div>
                            <div class="order">
                                <input type="text" name="sort" class="text input-mini"
                                                      value="{{$v['sort']}}">
                            </div>
                            <div class="order">{{$v['allow_publish']?'是':'否'}}</div>
                            <div class="name">
                                <span class="tab-sign"></span>
                                <input type="hidden" name="id" value="{{$v['id']}}">
                                <input type="text" name="title" class="text" value="{{$v['title']}}">
                                <a class="add-sub-cate" title="添加子分类"
                                   href="{{urlAdmin('GoodsCategory','getAdd',['pid'=>$v['id']])}}">
                                    <i class="icon-add"></i>
                                </a>
                                <span class="help-inline msg"></span>
                            </div>
                        </form>
                        </dt>
                        @if(!empty($v['_']))
                            <dd>
                            @foreach($v['_'] as $m)
                                <dl class="cate-item">
                                    <dt class="cf">
                                    <form action="{{urlAdmin('GoodsCategory','postEdit')}}" method="post">
                                        <div class="btn-toolbar opt-btn cf">
                                            <a title="编辑"
                                               href="{{urlAdmin('GoodsCategory','getEdit',['id'=>$m['id'],'pid'=>$m['pid']])}}">编辑</a>
                                            <a title="{{show_status_op($m['status'])}}"
                                               href="{{urlAdmin('GoodsCategory','anySetStatus',['ids'=>$m['id'],'status'=>abs(1-$m['status'])])}}"
                                               class="ajax-get">{{show_status_op($m['status'])}}</a>
                                            <a title="删除"
                                               href="{{urlAdmin('GoodsCategory','getRemove',['id'=>$m['id']])}}"
                                               class="confirm ajax-get">删除</a>
                                            <a title="移动"
                                               href="{{urlAdmin('GoodsCategory','getOperate',['type'=>'move'],2).'?from='.$m['id']}}">移动</a>
                                            <a title="合并"
                                               href="{{urlAdmin('GoodsCategory','getOperate',['type'=>'merge'],2).'?from='.$m['id']}}">合并</a>
                                        </div>
                                        <div class="fold"><i></i></div>
                                        <div class="order"><input type="text" name="sort" class="text input-mini"
                                                                  value="{{$m['sort']}}"></div>
                                        <div class="order">{{$m['allow_publish']?'是':'否'}}</div>
                                        <div class="name">
                                            <span class="tab-sign"></span>
                                            <input type="hidden" name="id" value="{{$m['id']}}">
                                            <input type="text" name="title" class="text" value="{{$m['title']}}">
                                            <a class="add-sub-cate" title="添加子分类"
                                               href="{{urlAdmin('GoodsCategory','getAdd',['pid'=>$m['id']])}}">
                                                <i class="icon-add"></i>
                                            </a>
                                            <span class="help-inline msg"></span>
                                        </div>
                                    </form>
                                    </dt>
                                </dl>
                            @endforeach
                            </dd>
                        @endif
                    </dl>
                @endforeach
            @else
                <div align="center">
                    <span style="text-align: center;font-size:15px;">aOh! 暂时还没有内容!</span>
                </div>
            @endif
        </div>
    </div>
    <!-- /表格列表 -->
@endsection
@section('script')
    <script type="text/javascript">
        (function ($) {
            /* 分类展开收起 */
            $(".category dd").prev().find(".fold i").addClass("icon-unfold")
                    .click(function () {
                        var self = $(this);
                        if (self.hasClass("icon-unfold")) {
                            self.closest("dt").next().slideUp("fast", function () {
                                self.removeClass("icon-unfold").addClass("icon-fold");
                            });
                        } else {
                            self.closest("dt").next().slideDown("fast", function () {
                                self.removeClass("icon-fold").addClass("icon-unfold");
                            });
                        }
                    });

            /* 三级分类删除新增按钮 */
            $(".category dd dd .add-sub").remove();

            /* 实时更新分类信息 */
            $(".category")
                    .on("submit", "form", function () {
                        var self = $(this);
                        $.post(
                                self.attr("action"),
                                self.serialize(),
                                function (data) {
                                    /* 提示信息 */
                                    var name = data.status ? "success" : "error", msg;
                                    msg = self.find(".msg").addClass(name).text(data.info)
                                            .css("display", "inline-block");
                                    setTimeout(function () {
                                        msg.fadeOut(function () {
                                            msg.text("").removeClass(name);
                                        });
                                    }, 1000);
                                },
                                "json"
                        );
                        return false;
                    })
                    .on("focus", "input", function () {
                        $(this).data('param', $(this).closest("form").serialize());

                    })
                    .on("blur", "input", function () {
                        if ($(this).data('param') != $(this).closest("form").serialize()) {
                            $(this).closest("form").submit();
                        }
                    });
        })(jQuery);
    </script>
@endsection
